package com.ebc.eservice.controller.app;

import com.ebc.eservice.service.cardStat.CardStatService;
import com.ebc.eservice.service.cardStat.ClientInteractService;
import com.ebc.eservice.util.JsonResult;
import com.ebc.eservice.util.MyTimeUtil;
import com.ebc.eservice.util.common.constant.ApiTextHelperConstant;
import com.ebc.eservice.util.common.constant.DeveloperConstant;
import com.ebc.eservice.vo.card.CardStatReqVo;
import com.ebc.eservice.vo.card.history.CardHistoryReqVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.Date;

/**
 * @author: Joey
 * @Description:名片曝光+客户管理
 * @date:2022/9/28 0:13
 */
@Api(tags = "小程序-名片管理-[曝光统计][客户管理]")
@RestController
@RequestMapping("/appCardExposureAndClient")
public class CardExposureClientController {

    @Autowired
    private CardStatService cardStatService;
    @Autowired
    private ClientInteractService interactService;

    @ApiOperation(value = "[曝光统计]获取访客概况+七日访客趋势", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getVisitStat")
    public JsonResult getVisitStat(Integer cardId){
        return  cardStatService.getVisitStat(cardId);
    }

    @ApiOperation(value = "[曝光统计]获取历史数据", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getHistoryData")
    public JsonResult getHistoryData(CardHistoryReqVo cardHistoryReqVo)  {
        System.out.println(cardHistoryReqVo.getBeginDate());
        System.out.println(cardHistoryReqVo.getEndDate());
        cardHistoryReqVo.setFlag(0);
        return cardStatService.getCardHistoryStat(cardHistoryReqVo);
    }

    @ApiOperation(value = "[曝光统计]获取全部历史数据", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getAllHistoryData")
    public JsonResult getAllHistoryData(CardHistoryReqVo cardHistoryReqVo) throws ParseException {

        MyTimeUtil myTimeUtil = new MyTimeUtil();
        Date dayBefore = myTimeUtil.SixtyDayBefore();
        cardHistoryReqVo.setBeginDate(dayBefore);
        cardHistoryReqVo.setEndDate(new Date());
        cardHistoryReqVo.setFlag(1);

        return cardStatService.getCardHistoryStat(cardHistoryReqVo);
    }


    //获取近7天客户趋势+客户概况（客户总量、近7日客户、今日客户）
    @ApiOperation(value = "[客户管理]获取客户概况+七日客户趋势", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getClientStat")
    public JsonResult getClient(Integer cardId){
        return interactService.getClientStat(cardId);
    }

    @ApiOperation(value = "[客户管理]全部客户信息", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getClientList")
    public JsonResult getAllClient(Integer cardId){
        return interactService.getAllClientStat(cardId);
    }

    @ApiOperation(value = "[客户管理]根据手机号获取指定客户记录", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @GetMapping("/getClientStatByPhone")
    public JsonResult getAllClient(Integer cardId,String phone){
        return interactService.getClientStatByPhone(cardId,phone);
    }



}
